class EquipmentAddController {
    constructor($rootScope, $scope, $cookieStore, $timeout, $state, ngDialog, dialogService, CpService, getCpList, iRunner){

    	var vm = this;

    	vm.$rootScope    = $rootScope;
    	vm.$cookieStore  = $cookieStore;
    	vm.$timeout 	 = $timeout;
    	vm.$state   	 = $state;
    	vm.ngDialog 	 = ngDialog;
    	vm.dialogService = dialogService;
    	vm.CpService     = CpService;
    	vm.getCpList     = getCpList;
    	vm.iRunner 	     = iRunner;

    	// 计时点列表
        vm.getCpList.code==0&&(vm.cplist = vm.getCpList.data);

        console.log(vm.cplist);
    }

    // 表单提交
    submitForm(isValid) {
        var vm = this;
        //验证失败的场合
        if (!isValid) {
            //设备名称为空的情况下
            if (!vm.equipmentName) {
                vm.ngDialog.open({
                    template: '<p>请添加设备名称</p>',
                    className: 'ngdialog-theme-default ngdialog-alert',
                    plain: true
                });
        } else if (!vm.cpPoint) {
                vm.ngDialog.open({
                    template: '<p>请选择关联计时点</p>',
                    className: 'ngdialog-theme-default ngdialog-alert',
                    plain: true
                });
            }
        } else {

            //验证成功的场合提交表单
            vm.ngDialog.open({
                template: '<p>添加成功</p>',
                className: 'ngdialog-theme-default ngdialog-alert',
                plain: true
            });
            // 重新载入页面
            vm.$state.reload();

        }
    }
}

EquipmentAddController.$inject = ['$rootScope', '$scope', '$cookieStore', '$timeout', '$state', 'ngDialog', 'dialogService', 'CpService', 'getCpList', 'iRunner']; 

export default EquipmentAddController;